import time, random
setGlobalDuration(20)

beginPythonInst(1)
soundfont(duration=2)
endPythonInst()

proc = startCsound()

time.sleep(2)

# let the function pit call itself over and over...
active = True

def pit():
    dict = {'soundfont': {}}
    dict['soundfont']['midipitch'] = random.randint(36,60)
    sendEvent(1, dict, proc)
    if active:
        oneCall(.25, pit)

# ... breaks the loop when the script is stoped
def onStop():
    global active
    active = False

pit()

